﻿using Delphi.Mimir.Data.Entities.Final;
using Delphi.Mimir.Data.Entities.Final.Mappings;
using Delphi.Mimir.Data.Entities.Raw;
using Delphi.Mimir.Data.Entities.Raw.Mappings;
using Delphi.Mimir.Migrations;
using System.Data.Entity;

namespace Delphi.Mimir.Config {
    public class DelphiContext : DbContext {
        public DelphiContext() : base("name=Delphi") {
            Database.SetInitializer<DelphiContext>(new Initializer());
        }

        /**********************************************************************
        /* Database Entities
        /*********************************************************************/
        // Raw Schema
        public virtual DbSet<RawSymbol> RawSymbols { set; get; }
        public virtual DbSet<RawQuote> RawQuotes { set; get; }
        public virtual DbSet<RawSymbolChange> RawSymbolChanges { set; get; }
        public virtual DbSet<RawSymbolSplit> RawSymbolSplits { set; get; }
        public virtual DbSet<RawCorporateAction> RawCorporateActions { set; get; }
        public virtual DbSet<RawFundamentals> RawFundamentals { set; get; }
        public virtual DbSet<RawIncomeStatement> RawIncomeStatements { set; get; }
        public virtual DbSet<RawBalanceSheet> RawBalanceSheets { set; get; }
        public virtual DbSet<RawCashFlow> RawCashFlows { set; get; }
        public virtual DbSet<RawEarningsEstimate> RawEarningsEstimates { set; get; }
        public virtual DbSet<RawEarningsHistory> RawEarningsHistories { set; get; }
        public virtual DbSet<RawEpsRevision> RawEpsRevisions { set; get; }
        public virtual DbSet<RawEpsTrend> RawEpsTrends { set; get; }
        public virtual DbSet<RawGrowthEstimate> RawGrowthEstimates { set; get; }
        public virtual DbSet<RawRevenueEstimate> RawRevenueEstimates { set; get; }
        

        // Stage Schema

        // Final Schenma
        public virtual DbSet<Parameter> Parameters { set; get; }
        public virtual DbSet<Country> Countries { set; get; }
        public virtual DbSet<Currency> Currencies { set; get; }
        public virtual DbSet<Category> Categories { set; get; }
        public virtual DbSet<Frequency> Frequencies { set; get; }
        public virtual DbSet<OptionType> OptionTypes { set; get; }
        public virtual DbSet<TimeZone> TimeZones { set; get; }
        public virtual DbSet<Symbol> Symbols { set; get; }
        public virtual DbSet<Exchange> Exchanges { set; get; }
        public virtual DbSet<LoadType> LoadTypoes { set; get; }
        public virtual DbSet<LoadControl> LoadControls { set; get; }
        public virtual DbSet<Load> Loads { set; get; }
        public virtual DbSet<SymbolChange> SymbolChanges { set; get; }
        public virtual DbSet<Quote> Quotes { set; get; }
        public virtual DbSet<CorporateAction> CorporateActions { set; get; }
        public virtual DbSet<CorporateActionType> CorporateActionTypes { set; get; }
        public virtual DbSet<Fundamentals> Fundamentals { set; get; }
        public virtual DbSet<Industries> Industries { set; get; }
        public virtual DbSet<Sectors> Sectors { set; get; }
        public virtual DbSet<FxRate> FxRates { set; get; }
        public virtual DbSet<FinancialStatement> FinancialStatements {set;get;}
        public virtual DbSet<Account> Accounts { set; get; }
        public virtual DbSet<Client> Clients { set; get; }
        public virtual DbSet<Portfolio> Portfolios { set; get; }
        public virtual DbSet<Transaction> Transactions { set; get; }
        public virtual DbSet<AssetUniverse> AssetUnivers { set; get; }
        public virtual DbSet<ManagedProduct> ManagedProducts { set; get; }
        public virtual DbSet<Order> Orders { set; get; }
        public virtual DbSet<OrderExecution> OrderExecutions { set; get; }
        public virtual DbSet<OrderConstraint> OrderConstraints { set; get; }
        public virtual DbSet<ManagedProductPosition> ManagedProductPositions { set; get; }
        public virtual DbSet<CashTransaction> CashTransactions { set; get; }
        


        /**********************************************************************
        /* Mapping / Configuration
        /*********************************************************************/
        protected override void OnModelCreating(DbModelBuilder modelBuilder) {
            base.OnModelCreating(modelBuilder);

            // Raw Schema
            modelBuilder.Configurations.Add(new RawSymbolMap());
            modelBuilder.Configurations.Add(new RawQuoteMap());
            modelBuilder.Configurations.Add(new RawSymbolChangeMap());
            modelBuilder.Configurations.Add(new RawSymbolSplitMap());
            modelBuilder.Configurations.Add(new RawCorporateActionMap());
            modelBuilder.Configurations.Add(new RawFundamentalsMap());
            modelBuilder.Configurations.Add(new RawIncomeStatementMap());
            modelBuilder.Configurations.Add(new RawBalanceSheetMap());
            modelBuilder.Configurations.Add(new RawCashFlowMap());
            modelBuilder.Configurations.Add(new RawEarningsEstimatesMap());
            modelBuilder.Configurations.Add(new RawEarningsHistoryMap());
            modelBuilder.Configurations.Add(new RawEpsRevisionMap());
            modelBuilder.Configurations.Add(new RawEpsTrendMap());
            modelBuilder.Configurations.Add(new RawEpsGrowthEstimateMap());
            modelBuilder.Configurations.Add(new RawRevenueEstimateMap());

            // Stage Schema

            // Final Stage
            modelBuilder.Configurations.Add(new ParameterMap());
            modelBuilder.Configurations.Add(new CountryMap());
            modelBuilder.Configurations.Add(new CurrencyMap());
            modelBuilder.Configurations.Add(new CategoryMap());
            modelBuilder.Configurations.Add(new FrequencyMap());
            modelBuilder.Configurations.Add(new OptionTypeMap());
            modelBuilder.Configurations.Add(new TimeZoneMap());
            modelBuilder.Configurations.Add(new SymbolMap());
            modelBuilder.Configurations.Add(new ExchangeMap());
            modelBuilder.Configurations.Add(new LoadTypeMap());
            modelBuilder.Configurations.Add(new LoadControlMap());
            modelBuilder.Configurations.Add(new LoadMap());
            modelBuilder.Configurations.Add(new SymbolChangeMap());
            modelBuilder.Configurations.Add(new QuoteMap());
            modelBuilder.Configurations.Add(new CorporateActionMap());
            modelBuilder.Configurations.Add(new CorporateActionTypeMap());
            modelBuilder.Configurations.Add(new FundamentalsMap());
            modelBuilder.Configurations.Add(new IndustryMap());
            modelBuilder.Configurations.Add(new SectorMap());
            modelBuilder.Configurations.Add(new FxRateMap());
            modelBuilder.Configurations.Add(new FinancialStatementMap());
            modelBuilder.Configurations.Add(new AccountMap());
            modelBuilder.Configurations.Add(new ClientMap());
            modelBuilder.Configurations.Add(new PortfolioMap());
            modelBuilder.Configurations.Add(new TransactionMap());
            modelBuilder.Configurations.Add(new AssetUniverseMap());
            modelBuilder.Configurations.Add(new ManagedProductMap());
            modelBuilder.Configurations.Add(new OrderMap());
            modelBuilder.Configurations.Add(new OrderExecutionMap());
            modelBuilder.Configurations.Add(new OrderConstraintMap());
            modelBuilder.Configurations.Add(new ManagedProductPositionMap());
            modelBuilder.Configurations.Add(new CashTransactionMap());
        }
    }
}
